#MakeList.txt: recast 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 2.8)

project ("recast")

option ( DEMO "using demo" ON )

# 注意发布的时候打开
if ( WIN32 AND NOT CYGWIN AND NOT ( CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" ) AND NOT ANDROID AND NOT DEMO)
	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT" CACHE STRING "")
	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd" CACHE STRING "")
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT" CACHE STRING "")
	set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd" CACHE STRING "")
endif ()

if ( ANDROID OR UNIX)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()

if ( IOS )
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode")
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode")
endif ()

# begin base
set(BASE_SRC
	base/src/ChunkyTriMesh.cpp
	base/src/Finalizer.cpp
	base/src/InputGeom.cpp
	base/src/MeshLoader.cpp
	base/src/Recast.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${BASE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${BASE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC base/include)
set(RECAST_SRC ${RECAST_SRC} ${BASE_SRC})
#end base

# begin fastlz
set(FASTLZ_SRC
	fastlz/fastlz.c)

if(NOT DEMO)
		set_property(
		SOURCE ${FASTLZ_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${FASTLZ_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC fastlz)
set(RECAST_SRC ${RECAST_SRC} ${FASTLZ_SRC})
#end fastlz

# begin detour
set(DETOUR_SRC
	detour/src/DetourAlloc.cpp
	detour/src/DetourAssert.cpp
	detour/src/DetourCommon.cpp
	detour/src/DetourLog.cpp
	detour/src/DetourNavMesh.cpp
	detour/src/DetourNavMeshBuilder.cpp
	detour/src/DetourNavMeshQuery.cpp
	detour/src/DetourNode.cpp
	detour/src/StreamHelper.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${DETOUR_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${DETOUR_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC detour/include)
set(RECAST_SRC ${RECAST_SRC} ${DETOUR_SRC})
#end detour

# begin detourcrowd
set(DETOUR_CROWD_SRC
	detourcrowd/src/DetourCrowd.cpp
	detourcrowd/src/DetourLocalBoundary.cpp
	detourcrowd/src/DetourObstacleAvoidance.cpp
	detourcrowd/src/DetourPathCorridor.cpp
	detourcrowd/src/DetourPathQueue.cpp
	detourcrowd/src/DetourProximityGrid.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${DETOUR_CROWD_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${DETOUR_CROWD_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC detourcrowd/include)
set(RECAST_SRC ${RECAST_SRC} ${DETOUR_CROWD_SRC})
#end detourcrowd


# begin detourtilecache
set(DETOUR_TILE_CACHE_SRC
	detourtilecache/src/DetourTileCache.cpp
	detourtilecache/src/DetourTileCacheBuilder.cpp
	)

if(NOT DEMO)
		set_property(
		SOURCE ${DETOUR_TILE_CACHE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${DETOUR_TILE_CACHE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC detourtilecache/include)
set(RECAST_SRC ${RECAST_SRC} ${DETOUR_TILE_CACHE_SRC})
#end detourtilecache

# begin fixedpoint
set(FIXEDPOINT_SRC
	fixedpoint/src/atanlooktbl.cpp
	fixedpoint/src/coslooktbl.cpp
	fixedpoint/src/fixed_lookuptbl.cpp
	fixedpoint/src/fixed64.cpp
	fixedpoint/src/fixed64_tool.cpp
	fixedpoint/src/fixed64Helper.cpp
	fixedpoint/src/sinlooktbl.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${FIXEDPOINT_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${FIXEDPOINT_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC fixedpoint/include)
set(RECAST_SRC ${RECAST_SRC} ${FIXEDPOINT_SRC})
#end fixedpoint

#begin race
set(RACE_SRC
	race/src/Race.cpp
	race/src/RaceTileCacheLoader.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${RACE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${RACE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC race/include)
set(RECAST_SRC ${RECAST_SRC} ${RACE_SRC})
#end race

#begin bridge
set(BRIDGE_SRC
	bridge/src/bridge.cpp
	bridge/src/bridge_for_render.cpp
	bridge/src/draw_helper.cpp)

if(NOT DEMO)
		set_property(
		SOURCE ${BRIDGE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		RECAST_LIB _CRT_SECURE_NO_WARNINGS)
else()
		set_property(
		SOURCE ${BRIDGE_SRC}
		APPEND
		PROPERTY COMPILE_DEFINITIONS
		_CRT_SECURE_NO_WARNINGS)
endif()

list(APPEND RECAST_INC bridge/include)
set(RECAST_SRC ${RECAST_SRC} ${BRIDGE_SRC})
#end bridge

if(DEMO)
	set(DEMO_SRC
		DemoApp.cpp)
	list(APPEND RECAST_INC .)
	set(RECAST_SRC ${RECAST_SRC} ${DEMO_SRC})
endif()

include_directories(recast ${RECAST_INC})

if (APPLE)
    if (IOS)
        set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
		if(DEMO)
			add_executable(recast	${RECAST_SRC})
		else()
			add_library(recast STATIC
			   ${RECAST_SRC}
			)
		endif()
		set_xcode_property (recast IPHONEOS_DEPLOYMENT_TARGET "7.0" "all")
    else ()
        ADD_DEFINITIONS(-DLUA_USE_MACOSX) #osx platform emmylua debugger must have this option or can not load cpath
        set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_64_BIT)")
		if(DEMO)
			add_executable(recast	${RECAST_SRC})
		else()
			add_library(recast MODULE
				${RECAST_SRC}
			)
		endif()
        set_target_properties ( recast PROPERTIES BUNDLE TRUE )
    endif ()
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Switch")
	if(DEMO)
		add_executable(recast	${RECAST_SRC})
	else()
		add_library(recast STATIC
			${RECAST_SRC}
		)
	endif()
    target_compile_options(recast PRIVATE -m64 -mcpu=cortex-a57+fp+simd+crypto+crc -fno-common -fno-short-enums -ffunction-sections -fdata-sections -fPIC -fms-extensions)
else ( )
	if(DEMO)
		add_executable(recast ${RECAST_SRC})
	else()
		add_library(recast SHARED
			${RECAST_SRC}
		)
	endif()
endif ( )

if ( WIN32 AND NOT CYGWIN  AND NOT DEMO)
    target_compile_definitions (recast PRIVATE RECAST_BUILD_AS_DLL)
endif ( )
# TODO: 如有需要，请添加测试并安装目标。

